//
//  OSTopicVideoView.m
//  百思不得姐
//
//  Created by PushMeBaby on 16/3/7.
//  Copyright © 2016年 CoderC. All rights reserved.
//

#import "OSTopicVideoView.h"
#import "OSTopic.h"
#import "OSShowPictureViewController.h"

#import "OSPlayVideoViewController.h"

#import "OSPlayViewController.h"
@interface OSTopicVideoView()


@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UILabel *payCountLabel;

@property (weak, nonatomic) IBOutlet UILabel *playTimeLabel;

@property (nonatomic,strong)NSURLRequest *request;

@end



@implementation OSTopicVideoView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
//
//-(WMPlayer *)playerView{
//    if (!_playerView) {
//        WMPlayer *playerView = [[WMPlayer alloc]initWithFrame:self.bounds videoURLStr:self.topic.videouri];
//        
//        [self addSubview:playerView];
//        _playerView = playerView;
//    }
//    return _playerView;
//}


+(instancetype)videoView{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
}

-(void)awakeFromNib{
    self.autoresizingMask = UIViewAutoresizingNone;
    
    self.imageView.userInteractionEnabled = YES;
    
    [self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPicture)]];
    

    
    
}

-(void)setTopic:(OSTopic *)topic{
    _topic = topic;
    
    self.imageView.hidden = NO;
    self.playButton.hidden = NO;
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:topic.middle_image]];
    
    self.payCountLabel.text = [NSString stringWithFormat:@"%zd播放",topic.playcount];
    NSInteger m = topic.videotime / 60;
    NSInteger s = topic.videotime % 60;
    self.playTimeLabel.text = [NSString stringWithFormat:@"%02zd:%02zd",m,s];
    

    
    
    
    self.webView.paginationBreakingMode = UIWebPaginationBreakingModeColumn;
   
    self.webView.paginationMode = UIWebPaginationModeLeftToRight;

    
}
- (IBAction)play:(UIButton *)sender {


    OSPlayVideoViewController *playVc = [[OSPlayVideoViewController alloc] init];
    playVc.topic = self.topic;
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:playVc animated:NO completion:nil];
    
   

}

- (void)showPicture
{
    OSShowPictureViewController *showPicture = [[OSShowPictureViewController alloc] init];
    showPicture.topic = self.topic;
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:showPicture animated:YES completion:nil];
}

@end
